﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WriteBugs.Library.Model;

namespace WriteBugs.Controls
{
    public class ListViewAdvNodeItem : IComparable<ListViewAdvNodeItem>
    {
        public string? Title => Excerpt?.Title;

        /// <summary>
        /// 类型：目录/摘抄
        /// </summary>
        public ExcerptType ExcerptType => (ExcerptType)(Excerpt?.ExcerptType);

        public string Icon => ExcerptType == ExcerptType.Catalog ? "../Images/FolderClose.png" : "../Images/Xaml.png";

        /// <summary>
        /// 跟随的Excerpt   
        /// </summary>
        public Excerpt? Excerpt { get; set; }

        public DateTime LastUpdateTime => (DateTime)(Excerpt?.LastUpdateTime);

        public string LastUpdateTimeStr
        {
            get
            {
                string time = "";
                if (Excerpt != null)
                {
                    DateTime now = DateTime.Now;
                    if (Excerpt.LastUpdateTime.Year == now.Year)
                    {
                        if (Excerpt.LastUpdateTime.Month == now.Month && Excerpt.LastUpdateTime.Day == now.Day)
                        {
                            time = $"{Excerpt.LastUpdateTime.Hour}:{Excerpt.LastUpdateTime.Minute}";
                        }
                        else
                        {
                            time = $"{Excerpt.LastUpdateTime.Month}-{Excerpt.LastUpdateTime.Day}";
                        }
                    }
                    else
                    {
                        time = $"{Excerpt.LastUpdateTime.Year}";
                    }
                }

                return time;
            }
        }

        public override string ToString()
        {
            return Title != null ? Title : "null";
        }

        public int CompareTo(ListViewAdvNodeItem? other)
        {
            return other == null ? 1 : other.LastUpdateTime.CompareTo(this.LastUpdateTime);
        }
    }
}
